﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Stock.物品信息
{
    public partial class Goods : Form
    {
        public Goods()
        {
            InitializeComponent();
        }

        

        private void Goods_Load(object sender, EventArgs e)
        {
            //取消自动列
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = DBH.Select("select * from Goods");

        }

        private void button1_Click(object sender, EventArgs e)
        {
            string Id = textBox1.Text;
            string GName = textBox2.Text;
            string Category = comboBox1.Text;
            string sql = $"select * from Goods where Id='{Id}', GName='{GName}',Category='{Category}'";
            dataGridView1.AutoGenerateColumns = false;
            dataGridView1.DataSource = DBH.Select(sql);

        }

        private void 添加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GoodsAddAndEdit GA = new GoodsAddAndEdit();
            GA.Show();
        }

        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GoodsAddAndEdit ga = new GoodsAddAndEdit();
            ga.Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value);
            ga.GName = dataGridView1.SelectedRows[0].Cells[1].Value.ToString();
           // ga.UnitePrice =dataGridView1.SelectedRows[0].Cells[2].Value.ToString();
            ga.Manufacture = dataGridView1.SelectedRows[0].Cells[3].Value.ToString();
            ga.Category = dataGridView1.SelectedRows[0].Cells[4].Value.ToString();

            ga.f = this;
            ga.Show();
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count > 0)
            {
                int Id = Convert.ToInt32(dataGridView1.SelectedRows[0].Cells[0].Value);
                string sql = $"delete from Goods where Id='{Id}'";
                if (DBH.NoSelect(sql) > 0)
                {
                    MessageBox.Show("删除成功！");
                    Goods_Load(null, null);
                }
                else
                {
                    MessageBox.Show("删除失败！");
                }
            }
        }
    }
}
